#include "UIInstructionImp.h"

extern int __start_shell_cmd;
extern int __stop_shell_cmd;
#define SHELL_CMD_START (ShellCmdEntry *)&__start_shell_cmd
#define SHELL_CMD_END (ShellCmdEntry *)&__stop_shell_cmd
void InitInstructionMap()
{
    ShellCmdEntry *item = SHELL_CMD_START;
    for (item = SHELL_CMD_START; item != SHELL_CMD_END; item++) {
        UIInstruction::RegisterInstruction(std::shared_ptr<UIInstruction>(item->inst));
    }
}

DemoCmd::DemoCmd()
{
    this->instName = "demo";
    this->helpInfo = "DemoCmd";
    this->argsInfo = "";
}

void DemoCmd::Execute(std::vector<std::string> &args)
{
    this->logger->Info("this is demo\n");
    for (const auto &item : args) {
        this->logger->Info(item + "\n");
    }
}
REGISTER_INSTRUCTION(DemoCmd);

ConfigReadCmd::ConfigReadCmd()
{
    this->instName = "config";
    this->helpInfo = "Read Config Test";
    this->argsInfo = "";
}

void ConfigReadCmd::Execute(std::vector<std::string> &args)
{
    this->logger->Info(config->Read("info") + "\n");
}
REGISTER_INSTRUCTION(ConfigReadCmd);

ExitCmd::ExitCmd()
{
    this->instName = "exit";
    this->helpInfo = "ExitCmd";
    this->argsInfo = "";
}

void ExitCmd::Execute(std::vector<std::string> &args)
{
    exit(0);
}
REGISTER_INSTRUCTION(ExitCmd);

HelpCmd::HelpCmd()
{
    this->instName = "help";
    this->helpInfo = "print help information";
    this->argsInfo = "";
}

void HelpCmd::Execute(std::vector<std::string> &args)
{
    std::string helpInfo;
    helpInfo += "========== HELP ==========\n";
    helpInfo += "Instruction Info:\n";
    for (const auto &item : UIInstruction::instructionMap) {
        helpInfo += item.second->GetHelp() + "\n";
    }
    this->logger->Print(helpInfo);
}
REGISTER_INSTRUCTION(HelpCmd);
